home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / wdj0696.zip / BURK.ZIP / TEST.C < prev    next >
C/C++ Source or Header  |  1996-04-04  |  5KB  |  141 lines

  1. // test.c - test out bugs and bug fixes for listview control
  2.  
  3. #include <windows.h>
  4. #include <windowsx.h>
  5. #include <commctrl.h>
  6.  
  7. #define MAIN_DLG   "MAINDIALOG"
  8. HINSTANCE CurrentInstance;
  9.  
  10. #define MASK LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH
  11.  
  12. LV_COLUMN   Columns[] = 
  13.     {
  14.     { MASK, LVCFMT_LEFT, 125, "Task",     4, 0 },
  15.     { MASK, LVCFMT_LEFT, 100, "Urgency",  7, 0 },
  16.     { MASK, LVCFMT_LEFT,  99, "Priority", 8, 0 },
  17.     };
  18. #define NCOLUMNS    (sizeof(Columns)/sizeof(LV_COLUMN))
  19. void    InitView(HWND ListView)
  20.     {
  21.     char Data[] = "abcdefghijklm";
  22.     int i;
  23.     for(i=0; i < NCOLUMNS; ++i)
  24.         ListView_InsertColumn(ListView, i, &Columns[i]);
  25.     for(i = 0; i < 4; ++i)
  26.         {
  27.         LV_ITEM Info;
  28.         memset(&Info, 0, sizeof(Info));
  29.         Info.mask   = LVIF_TEXT | LVIF_PARAM;
  30.         Info.pszText= Data +i;
  31.         Info.lParam = i;
  32.         ListView_InsertItem(ListView, &Info);
  33.         }
  34.     }
  35.  
  36.  
  37. #ifdef __BORLANDC__
  38.     #pragma argsused
  39. #endif
  40. static BOOL MainDialogCommand(HWND Dialog, int ControlId,
  41.                               HWND Control, UINT Notify)
  42.     {
  43.     if((ControlId == IDOK || ControlId == IDCANCEL)
  44.         && Notify == BN_CLICKED)
  45.         {
  46.         EndDialog(Dialog, ControlId);
  47.         return TRUE;
  48.         }
  49.     return FALSE;
  50.     }
  51.  
  52. static WNDPROC  OldProc;
  53.  
  54. int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, 
  55.     LPARAM lParamSort)
  56.     {
  57.     return lParam2 < lParam2 ? -1 : 1;
  58.     }
  59.  
  60.  
  61. #define YELLOW  RGB(255,255,0)
  62. BOOL CALLBACK MainDialog(HWND Dialog, UINT Message,
  63.                          WPARAM wParam, LPARAM lParam)
  64.     {
  65.     HWND    ListView = GetDlgItem(Dialog, 104);
  66.     switch(Message)
  67.         {
  68.         case    WM_INITDIALOG   :
  69.             {
  70.             char Buffer[16];
  71.             RECT Foo;
  72.             InitView(ListView);
  73.             ListView_SetBkColor(ListView, YELLOW);
  74.             ListView_SetTextBkColor(ListView, YELLOW);
  75.             int Width;
  76.             LV_COLUMN   Col;
  77.             memset(&Col, 0, sizeof(Col));
  78. #define BOGUS 99
  79.             Col.mask    = LVCF_WIDTH;
  80.             if(ListView_GetColumn(ListView, BOGUS, &Col))
  81.                 SetDlgItemInt(Dialog, 102, Col.cx, TRUE);
  82.             else
  83.                 SetDlgItemText(Dialog, 102, "ok!");
  84.             Width = ListView_GetColumnWidth(ListView, BOGUS);
  85.             SetDlgItemInt(Dialog, 101, Width, TRUE);
  86.             return TRUE;
  87.             }
  88.         HANDLE_MSG(Dialog, WM_COMMAND, MainDialogCommand);
  89.         case    WM_NOTIFY       :
  90.             {
  91.             NMHDR *Head = (NMHDR*)lParam;
  92.             HWND    Win = Head->hwndFrom;
  93.  
  94.             if(Head->code == NM_CLICK && IsDlgButtonChecked(Dialog, 103))
  95.                 {
  96.                 POINT   Mouse;
  97.                 GetCursorPos(&Mouse);
  98.                 ScreenToClient(Win, &Mouse);
  99.                 LV_HITTESTINFO  HitTest;
  100.                 HitTest.pt      = Mouse;
  101.                 ListView_HitTest(Win, &HitTest);
  102.                 int Width = ListView_GetColumnWidth(Win, 0);
  103.                 // if outside of item text but in first column
  104.                 if(!(HitTest.flags & LVHT_ONITEM) && HitTest.pt.x <= Width)
  105.                     {
  106.                     // force the hit to work if on a valid line
  107.                     HitTest.pt.x    = 1;
  108.                     ListView_HitTest(Win, &HitTest);
  109.                     if(HitTest.flags & LVHT_ONITEM)
  110.                         ListView_SetItemState(Win, HitTest.iItem, 
  111.                             LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED);
  112.                     }
  113.                 }
  114.  
  115.             else if(wParam == 104 && Head->code == LVN_BEGINLABELEDIT)
  116.                 return SetDlgMsgResult(Dialog, WM_NOTIFY, FALSE); // allow label editing
  117.             else if(wParam == 104 && Head->code == LVN_ENDLABELEDIT)
  118.                 {
  119.                 ListView_SortItems(GetDlgItem(Dialog, 104), SortFunc, 0);
  120.                 return SetDlgMsgResult(Dialog, WM_NOTIFY, 1);
  121.                 }
  122.             return FALSE;
  123.             break;
  124.             }
  125.         }
  126.     return FALSE; /* FALSE == we did not process msg */
  127.     }
  128.  
  129. #ifdef __BORLANDC__
  130.     #pragma argsused
  131. #endif
  132. int WINAPI WinMain(HINSTANCE Instance, HINSTANCE Previous,
  133.         LPSTR CommandLine, int ShowCommand)
  134.     {
  135.     InitCommonControls();
  136.     CurrentInstance    = Instance;
  137.     DialogBox(CurrentInstance, MAIN_DLG, NULL, MainDialog);
  138.     return 0;
  139.     }
  140.  
  141.